﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BlockMix.GamePanels
{
    /// <summary>
    /// Interaction logic for GamePanel.xaml
    /// </summary>
    public partial class PlayPanel : UserControl
    {
        public PlayPanel()
        {
            InitializeComponent();

            BackgroundWorker worker = null;
            IsVisibleChanged += (x, o) =>
                                         {
                                             if (Visibility != Visibility.Visible) return;
                                             worker = new BackgroundWorker();
                                             worker.DoWork += WorkDelegate;
                                             worker.RunWorkerAsync();
                                         };
            Unloaded += (x, o) =>
                                 {
                                     if (worker == null) return;
                                     worker.Dispose();
                                 };
        }

        void WorkDelegate(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                Dispatcher.Invoke(new Action(BlockTimer));
            }
        }

        void BlockTimer()
        {
            //var value = content1.GetValue(Canvas.LeftProperty);
            //var left = Convert.ToInt32(value.Equals(Double.NaN) ? 0 : value);
            //content1.SetValue(Canvas.LeftProperty, (double)(left + 10));
            content1.Left += 10;

            //blockTest.Left -= 10;

            //blockTest.TransformToAncestor(this).Transform(new Point(20, 0));
        }
    }
}
